package com.miya.cloud.erpdemo;

import com.miya.erpmofa.common.lang.request.single.PromoteCommodityItem;
import com.miya.erpmofa.common.lang.response.commodity.single.BaseInfo;
import com.miya.erpmofa.common.lang.response.commodity.single.CommodityInfo;
import com.miya.erpmofa.common.lang.response.member.MemberInfo;
import com.miya.erpmofa.common.lang.response.promote.single.PromoteRstInfo;
import com.miya.erpmofa.common.lang.response.promote.single.PromoteRstItem;
import com.miya.erpmofa.common.lang.response.ticket.TicketInfo;

import java.text.SimpleDateFormat;
import java.util.*;


/**
        *@author zhangminglei
        *@createTime 2018/9/13
        *@desc 
*/

public class DataGenerator {

    /**
     * @return CommodityInfo类型：商品查询应答类
     * @author zhangminglei
     * @params commodity_code: 商品编码
     * @createTime 2018/9/13
     * @desc 生成商品查询应答数据
     */

    public static CommodityInfo commodityInfoData(String commodity_code) {
        CommodityInfo commodityInfo = new CommodityInfo();
        BaseInfo baseInfo = new BaseInfo();

        baseInfo.setCommodity_code(commodity_code);
        baseInfo.setBarcode(CharacterUtils.getRandomString(10));
        baseInfo.setName(CharacterUtils.getRandomString(10));
        baseInfo.setUnit(CharacterUtils.getRandomString(10));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date now = new Date();
        baseInfo.setModify_time(sdf.format(now));
        baseInfo.setSpec_id(CharacterUtils.getRandomString(10));
        baseInfo.setIs_weight(false);
        baseInfo.setPrice(CharacterUtils.getRandomInt());
        commodityInfo.setBase_info(baseInfo);
        return commodityInfo;
    }

    /**
     * @return CommodityInfo类型：商品查询应答类
     * @author zhangminglei
     * @params card_no: 会员卡编码
     * @createTime 2018/9/13
     * @desc 生成商品查询应答数据
     */

    public static MemberInfo memberInfoData(String card_no) {
        MemberInfo memberInfo = new MemberInfo();
        memberInfo.setMember_id(CharacterUtils.getRandomString(10));
        memberInfo.setCard_no(card_no);
        return memberInfo;
    }

    /**
     * @param item_list 参与促销计算的商品清单
     * @return PromoteRstInfo类型：促销计算应答类
     * @author zhangminglei
     * @date 2018/9/13
     * @description 生成促销计算应答数据
     */

    public static PromoteRstInfo promoteRstInfoData(List<PromoteCommodityItem> item_list) {
        PromoteRstInfo promoteRstInfo = new PromoteRstInfo();
        ArrayList<PromoteRstItem> promoteRstItemList = new ArrayList<PromoteRstItem>();

        for (int i = 0; i < item_list.size(); i++) {
            PromoteRstItem promoteRstItem = new PromoteRstItem();
            promoteRstItem.setBarcode(item_list.get(i).getBarcode());
            promoteRstItem.setCommodity_code(CharacterUtils.getRandomString(10));
            promoteRstItem.setQuantity(item_list.get(i).getQuantity());
            promoteRstItem.setName(CharacterUtils.getRandomString(10));
            promoteRstItem.setOrigin_price(CharacterUtils.getRandomInt());
            promoteRstItem.setPromote_price(CharacterUtils.getRandomInt());
            promoteRstItemList.add(promoteRstItem);
        }
        promoteRstInfo.setItem_list(promoteRstItemList);
        promoteRstInfo.setTotal_final_amount(CharacterUtils.getRandomInt());
        promoteRstInfo.setTotal_origin_amount(CharacterUtils.getRandomInt());
        return promoteRstInfo;
    }

    /**
     * @return CommodityInfo类型：获取订单号小票号应答类
     * @author zhangminglei
     * @params
     * @createTime 2018/9/13
     * @desc 生成获取订单号小票号应答数据
     */
    public static TicketInfo ticketInfoData() {
        TicketInfo ticketInfo = new TicketInfo();
        ticketInfo.setOrder_no(CharacterUtils.getRandomString(10));
        ticketInfo.setTicket_no(CharacterUtils.getRandomString(10));
        return ticketInfo;
    }
}

